<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" href="__PUBLIC__/js/bootstrapvalidator/css/bootstrapValidator.min.css" />
    <script type="text/javascript" src="__PUBLIC__/js/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
</head>
<body>
<div class="modal-dialog" role="document" style="width:700px;">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="exampleModalLabel">审核会议预约 - {$meetingOrder.room.name}（最大预约时长：<span class="text-danger">{$meetingOrder.room.max_order_time}</span> 小时）</h4>
        </div>
        <form class="form-horizontal" style="padding-right: 17px;" id="approveForm">
            <input type="hidden" name="id" value="{$id}"/>
            <div class="panel-body">
                <div class="form-group">
                    <label class="control-label col-sm-3">预约时长:</label>
                    <div class="col-sm-3">
                        <div class="input-group">
                            <input type="text" class="form-control" name="" value="{$meetingOrder.length}" readonly>
                            <div class="input-group-addon">小时</div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-3">审核备注:</label>
                    <div class="col-sm-7">
                        <input type="text" class="form-control" name="reason" value="" placeholder="请输入审核备注">
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-3">是否通过:</label>
                    <div class="col-sm-6">
                        <input type="checkbox" name="_status" value="0" />
                        <input type="hidden" name="status" value="0" />
                    </div>
                </div>
            </div>
        </form>
        <div class="modal-footer">
            <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
            <button type="button" id="save" class="btn btn-primary">保存</button>
        </div>
    </div>
</div>

<script type="text/javascript">

    $(function(){
        $("#save").bind("click",doSave);
        initSwitchOption("_status","通过","不通过","0");
    });

    function initSwitchOption(name,onText,offText,state) {
        var switchOption = {
            onText: onText,
            offText: offText,
            onColor: "success",
            offColor: "info",
            state: state == 1 ? true : false,
            onSwitchChange: function (event, state) {
                if (state == true) {
                    $(this).val("1");
                } else {
                    console.log(state);
                    $(this).val("0");
                }
                var value = $(this).val();
                $("input:hidden[name='"+name.substring(1)+"']").val(value);
            }
        };
        $("input:checkbox[name='"+name+"']").bootstrapSwitch(switchOption);
    }

    function doSave(){
        if(!validateForm()){
            return false;
        }
        $.ajax({
            url: "{:U('Admin/Space/Meeting/doApprove')}",
            type: "post",
            dataType: "json",
            data: $("#approveForm").serialize(),
            success: function (data) {
                if(data.status){
                    common.alert("提示",data.msg,function(){
                        common.reload();
                    });
                }else{
                    commitFlag = false;
                    common.alert("提示",data.msg);
                }
            }
        });
    }

    function validateForm(){
        $('#approveForm').bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                //invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                reason: {
                    validators: {
                        notEmpty: {
                            message: '审核备注不能为空'
                        }
                    }
                }
            }
        });
        var data = $('#approveForm').data('bootstrapValidator');
        if (data) {
            data.validate();
            if (!data.isValid()) {
                return false;
            }
        }
        return true;
    }
</script>
</body>
</html>